Skip to content

[Rust] Rust support #1905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

ArjanSeijs
Copy link

Rust Support

This PR adds the initial setup for integrating rust in infer. Currently it calls a rust program that outputs the rust Intermediate Representation (MIR) of a file to analyze, eventually this MIR will be translated to textual for analysis.
The goal will be to detect memory errors in unsafe rust.

Examples of memory errors in rust:

let ptr: *const i32 = std::ptr::null();
unsafe {
    let x : i32 = *ptr; //Null dereference here
}
let ptr: *const i32; 
unsafe {
    {
        let x = Box::new(50); // Store 50 on the heap
        ptr = &*x;
    }
    // x dropped as it goes out of scope, rust will clean up x and free its memory on the heap
    let y = *ptr; // Undefined behavior: use after free
}

Technical

In infer/lib/rust is the rust program that will translate a rust program to textual.
It requires access to the internal rust compiler crate which are available on nightly builds of rust.
To run this program rustup can be installed https://rustup.rs/ to install the rust language and the rust package manager cargo.
The program is called from infer/src/integration/Rust.ml

Next Steps

  • Defining textual definitions in lib/rust/src/textual
  • Translations from MIR to textual.
  • Adding test procedures

The rust program uses a nightly build of rust to have acces to rusts compiler crate. Requires rustup: https://rustup.rs/ package to install the rust programming language and cargo package manager.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants